package de.hsowl.tod4a.global.xml;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import org.xmlpull.v1.XmlSerializer;

import android.util.Xml;
import de.hsowl.tod4a.global.model.ServerProperty;

public class SerializerHelper {

	private XmlSerializer serializer = Xml.newSerializer();
	private DataHelper data;

	public SerializerHelper(ServerProperty prop) {
		data = new DataHelper(prop);
	}

	public void setOutput(ByteArrayOutputStream os, String encoding) throws IllegalArgumentException, IllegalStateException,
			IOException {
		serializer.setOutput(os, encoding);
	}

	public void startTag(String namespace, String name) throws IllegalArgumentException, IllegalStateException, IOException {
		name = data.prepareString(name);
		serializer.startTag(namespace, name);
	}

	public void attribute(String namespace, String name, String value) throws IllegalArgumentException, IllegalStateException,
			IOException {
		value = data.prepareString(value);
		serializer.attribute(namespace, name, value);
	}

	public void setFeature(String name, boolean state) {
		serializer.setFeature(name, state);
	}

	public void endTag(String namespace, String name) throws IllegalArgumentException, IllegalStateException, IOException {
		name = data.prepareString(name);
		serializer.endTag(namespace, name);
	}

	public void text(String text) throws IllegalArgumentException, IllegalStateException, IOException {
		text = data.prepareString(text);
		serializer.text(text);
	}

	public void flush() throws IOException {
		serializer.flush();
	}
}
